<%@page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<link href="${apliPath}static/css/default.css" rel="stylesheet"
	type="text/css" />
<link rel="stylesheet" type="text/css"
	href="${apliPath}static/js/themes/metro-solidBlue/easyui.css" />
<link rel="stylesheet" type="text/css"
	href="${apliPath}static/js/themes/icon.css" />
<script type="text/javascript"
	src="${apliPath}static/js/jquery-1.10.2.js"></script>
<script type="text/javascript"
	src="${apliPath}static/js/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${apliPath}static/js/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
	$(function() {
		$("#manageMentor")
				.datagrid(
						{
							title : "作者列表",
							fit : true,
							border : false,
							toolbar : '#toolBar',
							iconCls : 'icon-search',
							fitColumns : true,
							url : "${apliPath}mentor/queryMentorsByPage",
							striped : true,
							loadMsg : "数据正在加载中，请稍等...",
							checkOnSelect : false,
							columns : [ [
									{
										field : "id",
										checkbox : true,
									},
									{
										title : "作者名称",
										field : "mentorName",
										width : 100,
									},
									{
										title : "在职状态",
										field : "useStatus",
										width : 70,
										formatter : function(value, row) {
											if (value == 0) {
												return "在职";
											} else {
												return "离职";
											}
										}
									},
									{
										title : "匿名名称",
										field : "nickName",
										width : 100,
										sortable : true,
									},
									{
										title : "密码",
										field : "password",
										width : 80,
									},
									{

										title : "编辑操作",
										field : "opt",
										width : 80,
										formatter : function(value, row, index) {
											return '<a class="delcls" onclick="delMentor('
													+ row.id
													+ ')" href="javascript:void(0)"></a><a class="modifycls" onclick="modifyMentor('
													+ index
													+ ')" href="javascript:void(0)"></a>';
										}

									} ] ],
							onLoadSuccess : function(data) {
								$('.delcls').linkbutton({
									text : '删除',
									plain : true,
									iconCls : 'icon-edit'
								});
								$('.modifycls').linkbutton({
									text : '更新',
									plain : true,
									iconCls : 'icon-edit'
								});
							},
							pagination : true,
							pageSize : 6,
							pageList : [ 3, 6, 9, 12 ],
							sortName : "nickName",
							sortOrder : "DESC",
							remoteSort : false,
						});

	});

	function modifyMentor(index) {
		var rows = $("#manageMentor").datagrid("getRows");
		$("#modify").show();
		$('#modify').form('load', {
			id : rows[index].id,
			mentorName : rows[index].mentorName,
			nickName : rows[index].nickName,
			password : rows[index].password,
			avatar : rows[index].avatar
		}), $("#modify").dialog({
			title : "修改",
			width : 450,
			height : 320,
			modal : true,
			buttons : [ {
				text : "确定",
				iconCls : 'icon-ok',
				plain : true,
				handler : function() {
					$("#modify").form("submit", {
						url : "${apliPath}mentor/modify",
						success : function(data) {
							$("#modify").dialog("close");
							$.messager.show({
								title : "提示框",
								msg : "更改成功",
							});
							$("#manageMentor").datagrid("reload");
						}
					});
				}
			}, {
				text : "取消",
				plain : true,
				iconCls : 'icon-cancel',
				handler : function() {
					$("#modify").form("reset");
					$("#modify").dialog("close");
				}
			} ],
		});
		if (rows[index].avatar != 'NOIMAGE') {
			document.getElementById("avatarImg").src = "${apliPath}static/file/mentor/avatar/"
					+ rows[index].avatar;
		}
		var select = document.getElementById("useStatus");
		select.innerHTML = "";
		var option = document.createElement("option");
		option.value = "0";
		var value1 = document.createTextNode("在职");
		option.appendChild(value1);
		select.appendChild(option);
		var option2 = document.createElement("option");
		option2.value = "1";
		var value2 = document.createTextNode("离职");
		option2.appendChild(value2);
		select.appendChild(option2);
	}
	function delMentor(index) {
		var transData = {
			drops : index,
		};
		$.post("${apliPath}mentor/drop", transData, function(data) {
		});
		$("#manageMentor").datagrid("reload");
	}
	function delMentors() {
		var rows = $("#manageMentor").datagrid("getSelections");
		var dropsArray = [];
		for (var i = 0; i < rows.length; i++) {
			dropsArray.push(rows[i].id);
		}
		$.post("${apliPath}mentor/drop", {
			"drops" : dropsArray.toString()
		}, function(data) {
		});
		$("#manageMentor").datagrid("reload");
	}
</script>

<table id="manageMentor">
</table>

<div id="toolBar" style="float: right">
	<table>
		<tr>
			<td><a href="javascript:void(0)" class="easyui-linkbutton"
				data-options="iconCls:'icon-cancel',plain:true"
				onclick="delMentors()"> 删除</a></td>
			<td><span style="font-size:12px">查询上师姓名</span>&nbsp;<input
				type="text" size="26px" value="此功能不可用，原因是没写" /></td>
		</tr>
	</table>
</div>
<form id="modify" style="display:none;top: 70" method="post"
	enctype="multipart/form-data">
	<input type="hidden" id="avatarChangeFlag" name="avatarChangeFlag">
	<input type="hidden" name="avatar"> <input type="hidden"
		name="id">
	<table style="margin:20px ">
		<tr>
			<td rowspan="3" width="60px"><img width="150" height="150"
				id="avatarImg"></td>
			<td valign="bottom">在职状态：</td>
			<td valign="bottom"><select name="useStatus" id="useStatus">
			</select></td>
		</tr>
		<tr>
			<td valign="bottom">上师名称：</td>
			<td valign="bottom"><input type="text" name="mentorName" /></td>
		</tr>
		<tr>
			<td>昵称名字：</td>
			<td><input type="text" name="nickName" /></td>
		</tr>
		<tr>
			<td align="center" style="height: 28">
				<div id="div_addPic"
					style="float:left;width:65px;height:20px;margin:4 15 0 10;background-image:url(${apliPath}static/images/addPic_out.png)">
					<input type="file" id="imageFile" name="avatarImg"
						style="width:81;filter:alpha(opacity=0);opacity:0;" width="81"
						onchange="change('avatarImg','imageFile')">
				</div>
				<div
					style="float:left;width:65px;height:20px;margin-top:4px;background-image:url(${apliPath}static/images/removePic_out.png)">
					<input style="width:81;filter:alpha(opacity=0);opacity:0;"
						width="81" onclick="removePicture()" type="button">
				</div>
			<td>密码：</td>
			<td><input name="password" type="text" /></td>
		</tr>
	</table>
</form>

<script type="text/javascript">
	function change(picId, fileId) {
		$('#avatarChangeFlag').val('ALCHANGE');
		var pic = document.getElementById(picId);
		var file = document.getElementById(fileId);
		var reallocalpath = "";
		if (window.FileReader) {// chrome,firefox7+,opera,IE10,IE9，IE9也可以用滤镜来实现
			oFReader = new FileReader();
			oFReader.readAsDataURL(file.files[0]);
			oFReader.onload = function(oFREvent) {
				pic.src = oFREvent.target.result;
			};
		} else if (document.all) {// IE8-
			reallocalpath = file.value;
			file.select();
			window.top.document.body.focus();
			// file.blur(); 执行该方法 会取消选中
			if (document.selection.createRange().text.length != 0
					&& document.selection.createRange().text != "") {
				reallocalpath = document.selection.createRange().text;
			}
			if (window.ie6) {
				pic.src = reallocalpath; // IE6浏览器设置img的src为本地路径可以直接显示图片
			} else { // 非IE6版本的IE由于安全问题直接设置img的src无法显示本地图片，但是可以通过滤镜来实现，IE10浏
				// 览器不支持滤镜，需要用FileReader来实现，所以注意判断FileReader先
				pic.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale',src=\""
						+ reallocalpath + "\")";
				pic.src = '';// 设置img的src为base64编码的透明图片，要不会显示红xx
			}
		} else if (file.files) {// firefox6-
			if (file.files.item(0)) {
				url = file.files.item(0).getAsDataURL();
				pic.src = url;
			}
		}
	}
	function removePicture() {
		$('#avatarChangeFlag').val('ALCHANGE');
		var file = document.getElementById("imageFile");
		if (file.outerHTML) {
			file.outerHTML = file.outerHTML;
		} else { // FF(包括3.5)
			file.value = "";
		}
		document.getElementById("avatarImg").removeAttribute('src');
		$("#avatarImg").css("filter", "");
	}
</script>
